# Contributor: Fernando Casas Schossow <casasfernando@outlook.com>
# Maintainer: Fernando Casas Schossow <casasfernando@outlook.com>
pkgname=ocaml-xml-light
_pkgname=xml-light
pkgver=2.4
pkgrel=2
pkgdesc="Minimal XML parser and printer for OCaml"
url="https://github.com/ncannasse/xml-light"
arch="all !riscv64" # limited by ocaml aport
license="LGPL-2.1-or-later-WITH-linking-exception"
makedepends="ocaml ocaml-findlib-dev ocaml-ocamldoc gawk"
subpackages="$pkgname-dev $pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/ncannasse/xml-light/archive/$pkgver.tar.gz
	Makefile-explicit-target-fix.patch"
builddir="$srcdir/$_pkgname-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	make all
	make doc
	make opt
}

check() {
	./test.exe <<EOF
<abc><123/></abc>

EOF
	./test_opt.exe <<EOF
<abc><123/></abc>

EOF
}

package() {
	export DESTDIR="$pkgdir"
	export OCAMLFIND_DESTDIR="$DESTDIR/usr/lib/ocaml"
	mkdir -p "$OCAMLFIND_DESTDIR" "$OCAMLFIND_DESTDIR/stublibs"
	rm -f test.cmi
	make install_ocamlfind
	install -D -m644 README "$pkgdir/usr/share/licenses/$pkgname/README"
	install -D -m644 -t "$pkgdir/usr/share/doc/$pkgname/html/" doc/*
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; for path in $(find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.cmx' -o \
			-name '*.cmxa' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\))
	do
		amove "$path"
	done
}

sha512sums="
029068c6eb48cd1223438dc0f86e1c5e6fd0412d160ea4d79928eec5e5f5843af46260d7240e4260851e9580e7f92d578c764c63c8e0acab348637455493ef02  ocaml-xml-light-2.4.tar.gz
6fd6d9131cb652df96c7fd7b68e9161a6e9a0c08fedfd2e2ee00a474d3d249ce16d4a8631a02ca36e158d8c61ff8fb0fe440b5e620eb64f865b23dcfd433e476  Makefile-explicit-target-fix.patch
"
